#include<vector>
#include<iostream>
#include<algorithm>
using std::max;
using std::vector;

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int maxSum = nums[0], dp = 0;
        for (const auto& x : nums) {
            dp = max(dp + x, x);
            maxSum = max(dp, maxSum);
        }
        return maxSum;

    }
};